export function formatDate(value, options = {}) {
  if (!value) {
    return '未知时间'
  }
  const date = new Date(value)
  if (Number.isNaN(date.getTime())) {
    return value
  }
  const defaultOptions = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
  }
  return date.toLocaleString('zh-CN', {
    hour12: false,
    ...defaultOptions,
    ...options,
  })
}

export function formatDateOnly(value) {
  return formatDate(value, {
    hour: undefined,
    minute: undefined,
  })
}

export function truncateText(text, maxLength = 120) {
  if (!text || text.length <= maxLength) {
    return text || ''
  }
  return `${text.slice(0, maxLength)}…`
}

